/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sgt.supermarket.hibernatedao;

import org.hibernate.Session;
import org.hibernate.criterion.Expression;
import sgt.supermarket.entity.Employee;

/**
 *
 * @author Administrator
 */
public class HibernateEmployeeDAO extends HibernateGenericDAO<Employee, Long> {

    public HibernateEmployeeDAO(Session session) {
        super(session);
    }

    public Employee getByUsername(String username) {
        return (Employee) getSession().createCriteria(Employee.class).add(Expression.eq("username", username)).uniqueResult();
    }

    public boolean checkLoginEmployee(String username, String password){
        boolean flag = false;
        for(Employee e : this.getAll()){
            if(e.getUsername().equals(username) && e.getPassword().equals(password)){
                flag = true;
            }
        }
        return flag;
    }

     public long getIdByUsernameAndPassword(String username, String password){
        long id = 0;
         for(Employee c : this.getAll()){
            if(c.getUsername().equals(username) && c.getPassword().equals(password))
                id = c.getAutoId();
        }
         return id;
    }
}
